package com.ict.web.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.Approval;
import com.ict.web.domain.ProjectManagement;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.ArrayList;

/**
 * @author xc
 */
@Data
public class ApprovalAddDto {

    /**审批id*/
    @ApiModelProperty(value = "审批id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long approvalId;

    /**项目id*/
    @ApiModelProperty(value = "项目id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long projectId;

    /**评审对象类型（0:三方1:专家2:项目管理3:项目单位）*/
    @ApiModelProperty(value = "评审对象类型（0:三方1:专家2:项目管理3:项目单位）")
    private String approvalType;

    /**阶段*/
    @ApiModelProperty(value = "阶段")
    private String approvalStage;

    /**节点*/
    @ApiModelProperty(value = "节点")
    private String approvalNode;


    /**开始时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone = "GMT+8")
    @ApiModelProperty(value = "开始时间")
    private LocalDateTime startTime;

    /**结束时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone = "GMT+8")
    @ApiModelProperty(value = "结束时间")
    private LocalDateTime endTime;

    /**操作人*/
    @ApiModelProperty(value = "操作人")
    private String approvalOperator;

    /**状态*/
    @ApiModelProperty(value = "状态")
    private String approvalStatus;

    /**操作/申报详情操作*/
    @ApiModelProperty(value = "操作/申报详情操作")
    private String approvalOperation;

    /**审批意见，varchar200*/
    @ApiModelProperty(value = "审批意见，varchar200")
//    @Xss(message = "用户昵称不能包含脚本字符")
//    @NotNull(message = "审批意见不能为空")
    @Size(max = 1000, message = "审批意见1-1000个字符")
    private String approvalOpinion;

    /**审核结果*/
    @ApiModelProperty(value = "审核结果")
    private String approvalResult;

    /**资料库{文件}*/
    @ApiModelProperty(value = "资料库{文件}")
    private YzqFileDTO approvalDatabase;
    /**
     * 将 ProjectManagementAddDto 转化为 ProjectManagement
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static Approval of(ApprovalAddDto dto){
        Approval bean = new Approval();
        BeanUtils.copyProperties(dto,bean);
        bean.setDelFlag(ProjectManagement.PROJECT_DECLARE);
        bean.setCreateTime(LocalDateTime.now());
        bean.setUpdateTime(LocalDateTime.now());
        return bean;
    }

    /**
     * 将 ApprovalAddDto中需传文件对象 转化为 file
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static ArrayList<YzqFile> toFile(Approval approval, ApprovalAddDto dto){
        ArrayList<YzqFile> fileList = new ArrayList<>();
        YzqFileDTO approvalDatabase = dto.getApprovalDatabase();

        YzqFile fileAdb = new YzqFile();
        fileAdb.setId(String.valueOf(IdUtils.snowId()));
        BeanUtils.copyProperties(approvalDatabase,fileAdb);
        fileList.add(fileAdb);
        approval.setApprovalDatabase(fileAdb.getId());
        return fileList;
    }
}
